/**
 * Copyright 2012 Fonfon.Fenceer
 * All rights reserved.
 * 
 * @project 
 * @author Fonfon.Fenceer
 * @version 1.0
 * @data 2012-3-18
 */
package com.guidecaptain.java.action;

import java.util.List;

import net.sf.json.JSONObject;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.guidecaptain.core.base.action.BaseAction;
import com.guidecaptain.java.model.vo.CertificateVO;
import com.guidecaptain.java.service.CertificateService;
import com.guidecaptain.java.service.ScanpicService;

/**
 * 
 * @author fenceer
 */
@Controller
@Scope("prototype")
public class CertificateAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Logger LOG = Logger.getLogger(CertificateAction.class);
	
	@Autowired
	private CertificateService certificateService;
	@Autowired
	private ScanpicService scanpicService;
	
	CertificateVO certificateVO=new CertificateVO();
	
	/**
	 * 添加证件信息
	 * @return
	 */
	public String insertCertificate(){
			certificateService.insertCertificate(certificateVO);
			
			return "insert";

	}
	
	public String queryCertificate(){
		CertificateVO certificate=certificateService.queryCertificate(certificateVO.getCtfId());
		try {
			PropertyUtils.copyProperties(certificateVO, certificate);

		} catch (Exception e) {
			LOG.error(e);
			return ERROR;
		}
		
		certificateVO.setScanpics(scanpicService.queryScanpicList(certificateVO.getCtfId()));
		
		return "ctfInfo";
	}
	
	/**
	 * 导游领队证件信息
	 * @return
	 */
	public String queryCertificateList(){
		List<CertificateVO> certificateList=certificateService.queryCertificateList(certificateVO.getGuideId());
		certificateList=certificateList.size()>0?certificateList:null;
		certificateVO.setCertificateList(certificateList);

		return "ctfList";
	}
	
	public String checkCtfRemind() {
		JSONObject jsonObject=new JSONObject();
		jsonObject.put("state", certificateService.checkCtfRemind(certificateVO.getGuideId()));
		
		setJsonObject(jsonObject);
		return JSON;
	}

	/** 
	 * @param 
	 * @return 
	 */
	@Override
	public Object getModel() {
		
		return certificateVO;
	}

}
